package com.duckclouddrive.controller;

import com.duckclouddrive.annotation.GlobalInterceptor;
import com.duckclouddrive.annotation.VerifyParam;
import com.duckclouddrive.entity.dto.SessionWebUserDto;
import com.duckclouddrive.entity.enums.FileDelFlagEnums;
import com.duckclouddrive.entity.po.FileInfo;
import com.duckclouddrive.entity.query.FileInfoQuery;
import com.duckclouddrive.entity.vo.FileInfoVO;
import com.duckclouddrive.entity.vo.PaginationResultVO;
import com.duckclouddrive.entity.vo.ResponseVO;
import com.duckclouddrive.service.FileInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.scanner.Constant;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController("recycleController")
@RequestMapping("/recycle")
public class RecycleController extends ABaseController{
    @Resource
    // 文件信息业务接口，用于操作文件信息
    private FileInfoService fileInfoService;

    /**
     * 查询回收站列表
     *
     * @param session 用户会话，用于获取用户信息
     * @param pageNo 页码
     * @param pageSize 页面大小
     * @return 返回回收站文件列表的响应对象
     */
    @RequestMapping("/loadRecycleList")
    @GlobalInterceptor
    public ResponseVO loadRecycleList(HttpSession session, Integer pageNo, Integer pageSize) {
        // 创建文件信息查询对象
        FileInfoQuery query = new FileInfoQuery();
        // 设置查询用户ID
        query.setUserId(getUserInfoFromSession(session).getUserId());
        // 设置查询页码和页面大小
        query.setPageNo(pageNo);
        query.setPageSize(pageSize);
        // 设置删除标志为回收站
        query.setDelFlag(FileDelFlagEnums.RECYCLE.getFlag());
        // 调用服务方法，分页查询回收站文件列表
        PaginationResultVO result = fileInfoService.findListByPage(query);
        // 将查询结果转换为分页VO并返回成功响应
        return getSuccessResponseVO(convert2PaginationVO(result, FileInfoVO.class));
    }
    @RequestMapping("/recoverFile")
    @GlobalInterceptor(checkParams = true)
    public ResponseVO recoverFile(HttpSession session, @VerifyParam(required = true) String fileIds) {
        SessionWebUserDto webUserDto = getUserInfoFromSession(session);
        fileInfoService.recoverFileBatch(webUserDto.getUserId(), fileIds);
        return getSuccessResponseVO(null);
    }
    @RequestMapping("/delFile")
    @GlobalInterceptor(checkParams = true)
    public ResponseVO delFile(HttpSession session, @VerifyParam(required = true) String fileIds) {
        SessionWebUserDto webUserDto = getUserInfoFromSession(session);
        fileInfoService.delFileBatch(webUserDto.getUserId(), fileIds,false);
        return getSuccessResponseVO(null);
    }
}
